<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <link
      rel="stylesheet"
      type="text/css"
      href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.43.0/codemirror.css"
    />
    <link
      rel="stylesheet"
      type="text/css"
      href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.43.0/addon/lint/lint.css"
    />
    <link
      rel="stylesheet"
      type="text/css"
      href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.43.0/theme/neo.css"
    />
    <link rel="stylesheet" type="text/css" href="./css/example.css" />
    <link rel="stylesheet" href="../dist/toastui-chart.css" />
    <title>13.2 [ColumnLine Chart] Live Update</title>
  </head>
  <body>
    <div class="description">
      You can see the tutorial
      <a href="https://github.com/nhn/tui.chart/blob/main/docs/en/common-liveUpdate-options.md" target="_blank">here</a>
      <br />
      <strong
        >The example code can be slower than your environment because the code is transpiled by
        babel-standalone in runtime.</strong
      >
    </div>
    <div class="wrap">
      <div class="code-html" id="code-html">
        <div id="chart-area"></div>
      </div>
      <div class="custom-area">
        <div id="error-dim">
          <span id="error-text"></span>
          <div id="error-stack"></div>
          <span id="go-to-dev-tool"
            >For more detail, open browser's developer tool and check it out.</span
          >
        </div>
        <div class="try-it-area">
          <h3>try it</h3>
          <textarea id="code"></textarea>
          <div class="apply-btn-area">
            <button class="btn" onclick="evaluationCode(chartCM, codeString);">Run it!</button>
          </div>
        </div>
      </div>
    </div>
    <script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
    <script src="../dist/toastui-chart.js"></script>
    <script class="code-js" id="code-js" type="text/babel">
      const el = document.getElementById('chart-area');
      const data = {
        categories: ['1', '2', '3', '4', '5'],
        series: {
          column: [
            {
              name: 'A',
              data: [10, 17, 22, 10, 40],
            },
            {
              name: 'B',
              data: [9.9, 16.0, 21.2, 24.2, 23.2],
            },
            {
              name: 'C',
              data: [18.3, 15.2, 12.8, 11.8, 13.0],
            },
            {
              name: 'D',
              data: [4.4, 12.2, 16.3, 18.5, 16.7],
            },
          ],
          line: [
            {
              name: 'E',
              data: [11, 40.1, 24.8, 30.7, 19.5],
            },
          ],
        },
      };
      const options = {
        chart: { title: '24-hr Average Temperature', width: 900, height: 500 },
        yAxis: { title: 'Temperature (Celsius)' },
        xAxis: { title: 'Month' },
        series: { shift: true },
      };

      const chart = toastui.Chart.columnLineChart({ el, data, options });

      let idx = 6;
      const intervalId = setInterval(() => {
        const randomData = [0, 1, 2, 3].map(() => Math.round(Math.random() * 100));
        chart.addData(randomData, idx.toString(), 'column');
        chart.addData([randomData[0]], idx.toString(), 'line');
        if (idx === 20) {
          clearInterval(intervalId);
        }
        idx += 1;
      }, 2500);
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.59.0/codemirror.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.59.0/addon/edit/matchbrackets.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.59.0/addon/selection/active-line.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.59.0/mode/javascript/javascript.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.59.0/addon/lint/lint.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.59.0/addon/lint/javascript-lint.js"></script>
    <script src="./js/example.js" type="text/babel"></script>
  </body>
</html>
